const { mongoose, db } = require('../utils/mongoose')

let schema = mongoose.Schema({
    id: { type: String, required: true },
    date: { type: Date, required: true },
    todo: { type: String, required: true },
    type: { type: String, required: false },
    status: { type: String, required: false },
    value: { type: Number, required: false },
    coin: { type: Number, required: false },
})

let Collection = mongoose.model('todos', schema)

// 新增
const add = (data) => {
    let model = new Collection(data)
    return model.save()
        .then(res => res)
        .catch(err => {
            return err;
        })
}

//查找
const query = (query = {}, page = { skip: 0, limit: 0 }) => {
    return Collection.find(query).limit(page.limit).skip(page.skip)
        .then(res => res)
        .catch(err => {
            console.log(err);
            return false;
        })
}
//更新
const updateUserInfo = (query, updated) => {
    return Collection.updateOne(query, updated)
        .then(res => res)
        .catch(err => {
            console.log(err);
            return false;
        })
}
module.exports = {
    add,
    query
    // updateUserInfo
}